#include<stdlib.h>
#include<stdio.h>

#define LEN 10

int length(int *a);
void show(int a[]);
int del(int *a,int index);
int insert(int *a,int index,int value);

/**
 * 
 * main function
*/
int main(int argc,char** argv)
{
    int a[LEN]={1,2,3,4,5};
    //del(a,2);
    insert(a,2,9);
    printf("the length of array a is %d\n",length(a));
    show(a);
    return 0;
}



int length(int* a)
{
    int j=0;
    while (j<LEN)
    {
        if( a[j] == 0 )
            break;
        else
            j++;   
    }
    return j;
}



void show(int a[])
{
    int len = length(a);
    for(int i=0;i<len;i++)
    {
        printf("%3d",a[i]);
    }
    printf("\n");
}

int del(int *a,int index)
{
    int len = length(a);

    if( len==0 || index > len -1 || index <0) 
    {
        return 0;
    }
    else
    {
        for(int i=index+1;i<len;i++)
        {
            a[i-1] = a[i];
        }
        a[len -1] = 0;
    }
    
}

int insert(int *a,int index, int value)
{
    int len =length(a);
    if(len >= LEN || index <0 || index > len)
        return 0;
    else
    {
        for(int i= len -1;i>=index;i--)
        {
            a[i+1] = a[i];
        }
        a[index] = value;
        return 1;
    }
    
}